import {Injectable} from '@angular/core';
import {HttpService} from '@kylin/http';

@Injectable({
    providedIn: 'root'
})

export class UserDetailService {

    constructor(private http: HttpService) {
    }
    getRole() {
        return [
            {label: '普通用户', value: 'USER'},
            {label: '草地管理员', value: 'GRASSLAND_ADMIN'},
            {label: '林地管理员', value: 'FOREST_ADMIN'},
            {label: '耕地管理员', value: 'CULTIVATION_ADMIN'}
        ];
    };
    getSex() {
        return [
            {label: '男', value: 1},
            {label: '女', value: 2},
        ]
    }
    getType() {
        return [
            {label: '草地', value: 1},
            {label: '耕地', value: 2},
            {label: '林地', value: 3},
            {label: '其他', value: 4}
        ]
    }
    getEnabled() {
        return [
            {label: '启用', value: true},
            {label: '禁用', value: false},
        ]
    }
    addUser(userInfo) {
        this.processParams(userInfo);
        return this.http.post('/users/register', userInfo);
    }
    processParams(params) {
        Object.keys(params).map(key => {
            params[key] = (params[key] === null || params[key] === 'undefined') ? '' : params[key];
        });
    }
}
